<% content_for :page_title do %>
  <%= plural_resource_name(Spree::StockTransfer) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:new_stock_transfer), new_admin_stock_transfer_path, { :icon => 'add', :class => 'btn-success' } %>
<% end if can? :create, Spree::StockTransfer %>

<div data-hook="admin_orders_index_search" class="well">
  <fieldset>
    <legend><%= Spree.t(:search) %></legend>
    <%= search_form_for @q, :url => admin_stock_transfers_path do |f| %>

      <div class="row no-marginb">
        <div class="col-md-4">
          <div class="form-group">
            <%= f.label :reference_cont, Spree.t(:reference_contains) %>
            <%= f.text_field :reference_cont, class: 'form-control' %>
          </div>
        </div>

        <div class="col-md-4">
          <div class="form-group">
            <%= f.label :source_location, Spree.t(:source) %>
            <%= f.select :source_location_id_eq,
                 options_from_collection_for_select(@stock_locations, :id, :name, @q.source_location_id_eq),
                 { include_blank: true }, class: 'select2' %>
          </div>
        </div>

        <div class="col-md-4">
          <div class="form-group">
            <%= f.label :destination_location, Spree.t(:destination) %>
            <%= f.select :destination_location_id_eq,
                 options_from_collection_for_select(@stock_locations, :id, :name, @q.destination_location_id_eq),
                 { include_blank: true }, class: 'select2' %>
          </div>
        </div>
      </div>

      <div class="form-actions">
        <div data-hook="admin_stock_transfers_index_search_buttons">
          <%= button Spree.t(:filter_results), 'search' %>
        </div>
      </div>
    <% end %>
  </fieldset>
</div>

<% if @stock_transfers.any? %>
  <table class="table" id='listing_stock_transfers' data-hook>
    <thead>
      <tr data-hook='stock_transfers_header'>
        <th><%= Spree.t(:created_at) %></th>
        <th><%= Spree.t(:reference) %></th>
        <th><%= Spree.t(:source) %></th>
        <th><%= Spree.t(:destination) %></th>
        <th class='actions'></th>
      </tr>
    </thead>
    <tbody>
      <% @stock_transfers.each do |stock_transfer| %>
        <tr id="<%= spree_dom_id stock_transfer %>" data-hook="stock_transfer_row">
          <td><%= link_to stock_transfer.created_at, admin_stock_transfer_path(stock_transfer) %></td>
          <td><%= stock_transfer.reference %></td>
          <td><%= stock_transfer.source_location.try(:name) %></td>
          <td><%= stock_transfer.destination_location.try(:name) %></td>
          <td class="actions actions-1">
            <%= link_to_with_icon 'show', Spree.t(:show), admin_stock_transfer_path(stock_transfer), :class => 'btn btn-default btn-sm', :no_text => true, :data => {:action => 'view'} %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <div class="alert alert-info no-objects-found">
    <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::StockTransfer)) %>,
    <%= link_to(Spree.t(:add_one), new_admin_stock_transfer_path) if can? :create, Spree::StockTransfer %>!
  </div>
<% end %>

<%= paginate @stock_transfers %>
